package com.imufe.chemicalenterprisedangerwarning.controller;

import com.imufe.chemicalenterprisedangerwarning.entity.query.CreateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.query.RegionQuery;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.RegionVO;
import com.imufe.chemicalenterprisedangerwarning.service.RegionService;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author BaiBan
 * @since 2022-09-20
 */
@Api(tags = "区域")
@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    RegionService service;

    @ApiOperation("某区域的子区域集合")
    @GetMapping("/child/list")
    public ResponseEntity<List<RegionVO>> childList(Long id) {
        List<RegionVO> list = service.regionList(id);
        return ResponseEntity.success(list);
    }

    @ApiOperation(value = "新增", notes = "新增一个区域，返回新增的区域")
    @PostMapping("/create")
    public ResponseEntity<RegionVO> create(@RequestBody @Validated(CreateGroup.class) RegionQuery query) {
        RegionVO vo = service.create(query);
        return ResponseEntity.success(vo);
    }
}